// 所有接口方法
var Promise = require('../bluebird/index.js')
var common = require('./domain.js')
var apiDomain = common.CONST.apiDoamin

function newAjaxPromise(url, data, type) {
	return new Promise(function(res, rej) {
		if(url == null || url == '') {
			rej('url is empty')
			return;
		}
		wx.request({
			method: type || "GET",
			data: data,
			header: {
				signature: wx.getStorageSync('token')
			},
			url: apiDomain + url,
			success: function(resp) {
				if(resp.statusCode == 200) {
					res(resp.data)
				} else {
					rej(typeof resp.data == 'string' && resp.data || resp.data.msg || resp.data.message || resp.statusCode)
				}
			},
			fail: function(resp) {
				rej(resp.errMsg || JSON.stringify(resp))
			}
		});

	})
}

//获取商品信息
exports.getBindInfo = function(data) {
	return newAjaxPromise('/self/getBindInfo', data)
}

exports.deleteImg = function(data) {
	return newAjaxPromise('/util/deleteImg', data, 'POST')
}
